package com.bjpowernode.controllers;

import com.bjpowernode.entities.TClue;
import com.bjpowernode.result.Result;
import com.bjpowernode.services.ClueService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class ClueController {
    @Resource
    private final ClueService clueService;

    public ClueController(ClueService clueService) {
        this.clueService = clueService;
    }

    @GetMapping(value = "/api/clue/{id}")
    public Result getClueById(@PathVariable(value = "id") Integer id) {
        TClue tClue = clueService.getClueById(id);
        return Result.OK(tClue);
    }

    @GetMapping(value = "/api/clues")
    public Result getCluesByPage(@RequestParam(value = "current") Integer current) {
        PageInfo<TClue> pageInfo = clueService.getCluesByPage(current);
        return Result.OK(pageInfo);
    }

    @PostMapping(value = "/api/importExcel")
    public Result importExcel(MultipartFile excelFile) throws IOException {
        clueService.importExcel(excelFile.getInputStream());
        return Result.OK();
    }
}
